In [1]:
import pandas as pd

In [2]:
import pulp as opt

In [15]:
df = pd.read_csv('data_movies_week_9.csv', header = None)

In [16]:
df


Out[16]:
0 1 2 3
0 1 Star Trek 6.100000e+07 720
1 2 Ice Age 3.300000e+07 459
2 3 Secret Life 2.550000e+07 334
3 4 Ghostbusters 2.075000e+07 285
4 5 Lights Out 1.700000e+07 223
5 6 Hillary's America 7.801226e+06 100
6 7 The Legend Of 6.300000e+06 78
7 8 Finding Dory 6.200000e+06 73
8 9 Mike and Dave 3.450000e+06 51
9 10 The Infiltrator 3.276515e+06 42
10 11 Central Intellience 3.225000e+06 41
11 12 The Purge 3.100000e+06 36
12 13 The BFG 1.794282e+06 23
13 14 The Shallows 1.716270e+06 22
14 15 AbsolutelyFa 1.404221e+06 18
15 16 Empty -2.000000e+06 0
Declare variables

In [17]:
x1 = opt.LpVariable('x1',0,8, cat = 'Integer')
x2 = opt.LpVariable('x2',0,8, cat = 'Integer')
x3 = opt.LpVariable('x3',0,8, cat = 'Integer')
x4 = opt.LpVariable('x4',0,8, cat = 'Integer')
x5 = opt.LpVariable('x5',0,8, cat = 'Integer')
x6 = opt.LpVariable('x6',0,8, cat = 'Integer')
x7 = opt.LpVariable('x7',0,8, cat = 'Integer')
x8 = opt.LpVariable('x8',0,8, cat = 'Integer')
x9 = opt.LpVariable('x9',0,8, cat = 'Integer')
x10 = opt.LpVariable('x10',0,8, cat = 'Integer')
x11 = opt.LpVariable('x11',0,8, cat = 'Integer')
x12 = opt.LpVariable('x12',0,8, cat = 'Integer')
x13 = opt.LpVariable('x13',0,8, cat = 'Integer')
x14 = opt.LpVariable('x14',0,8, cat = 'Integer')
x15 = opt.LpVariable('x15',0,8, cat = 'Integer')
x16 = opt.LpVariable('x16',0,8, cat = 'Integer')
Declare objective

In [18]:
prob = opt.LpProblem('Optimize_FML_Success',opt.LpMaximize)

In [19]:
prob += df.ix[0,2]*x1 + df.ix[1,2]*x2 + df.ix[2,2]*x3 + df.ix[3,2]*x4 + df.ix[4,2]*x5 + df.ix[5,2]*x6 + df.ix[6,2]*x7 + df.ix[7,2]*x8 + df.ix[8,2]*x9 + df.ix[9,2]*x10 + df.ix[10,2]*x11 + df.ix[11,2]*x12 + df.ix[12,2]*x13 + df.ix[13,2]*x14 + df.ix[14,2]*x15 + df.ix[15,2]*x16

In [20]:
prob


Out[20]:
Optimize_FML_Success:
MAXIMIZE
61000000.0*x1 + 3276514.912*x10 + 3225000.0*x11 + 3100000.0*x12 + 1794281.975*x13 + 1716269.716*x14 + 1404220.676*x15 + -2000000.0*x16 + 33000000.0*x2 + 25500000.0*x3 + 20750000.0*x4 + 17000000.0*x5 + 7801225.98*x6 + 6300000.0*x7 + 6200000.0*x8 + 3450000.0*x9 + 0.0
VARIABLES
0 <= x1 <= 8 Integer
0 <= x10 <= 8 Integer
0 <= x11 <= 8 Integer
0 <= x12 <= 8 Integer
0 <= x13 <= 8 Integer
0 <= x14 <= 8 Integer
0 <= x15 <= 8 Integer
0 <= x16 <= 8 Integer
0 <= x2 <= 8 Integer
0 <= x3 <= 8 Integer
0 <= x4 <= 8 Integer
0 <= x5 <= 8 Integer
0 <= x6 <= 8 Integer
0 <= x7 <= 8 Integer
0 <= x8 <= 8 Integer
0 <= x9 <= 8 Integer
Declare constraints
1) We must fill 8 theaters

In [21]:
prob += x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16 <= 8

In [22]:
prob += x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16 >= 8
2) We must limit ourselves to 1000 FML bucks

In [23]:
prob += df.ix[0,3]*x1 + df.ix[1,3]*x2 + df.ix[2,3]*x3 + df.ix[3,3]*x4 + df.ix[4,3]*x5 + df.ix[5,3]*x6 + df.ix[6,3]*x7 + df.ix[7,3]*x8 + df.ix[8,3]*x9 + df.ix[9,3]*x10 + df.ix[10,3]*x11 + df.ix[11,3]*x12 + df.ix[12,3]*x13 + df.ix[13,3]*x14 + df.ix[14,3]*x15 + df.ix[15,3]*x16 <= 1000
Solve the problem

In [24]:
opt.pulpTestAll()


	 Testing zero subtraction
	 Testing inconsistant lp solution
	 Testing continuous LP solution
	 Testing maximize continuous LP solution
	 Testing unbounded continuous LP solution
	 Testing Long Names
	 Testing repeated Names
	 Testing zero constraint
	 Testing zero objective
	 Testing LpVariable (not LpAffineExpression) objective
	 Testing Long lines in LP
	 Testing LpAffineExpression divide
	 Testing MIP solution
	 Testing MIP solution with floats in objective
	 Testing MIP relaxation
	 Testing feasibility problem (no objective)
	 Testing an infeasible problem
	 Testing an integer infeasible problem
	 Testing column based modelling
	 Testing dual variables and slacks reporting
	 Testing fractional constraints
	 Testing elastic constraints (no change)
	 Testing elastic constraints (freebound)
	 Testing elastic constraints (penalty unchanged)
	 Testing elastic constraints (penalty unbounded)
* Solver <class 'pulp.solvers.PULP_CBC_CMD'> passed.
Solver <class 'pulp.solvers.CPLEX_DLL'> unavailable
Solver <class 'pulp.solvers.CPLEX_CMD'> unavailable
Solver <class 'pulp.solvers.CPLEX_PY'> unavailable
Solver <class 'pulp.solvers.COIN_CMD'> unavailable
Solver <class 'pulp.solvers.COINMP_DLL'> unavailable
Solver <class 'pulp.solvers.GLPK_CMD'> unavailable
Solver <class 'pulp.solvers.XPRESS'> unavailable
Solver <class 'pulp.solvers.GUROBI'> unavailable
Solver <class 'pulp.solvers.GUROBI_CMD'> unavailable
Solver <class 'pulp.solvers.PYGLPK'> unavailable
Solver <class 'pulp.solvers.YAPOSIB'> unavailable

In [25]:
status = prob.solve(opt.PULP_CBC_CMD(msg=0))

In [26]:
opt.LpStatus[status]


Out[26]:
'Optimal'

In [27]:
for v in prob.variables():
    print (v.name, "=" , v.varValue)


x1 = 1.0
x10 = 0.0
x11 = 1.0
x12 = 4.0
x13 = 0.0
x14 = 1.0
x15 = 0.0
x16 = 0.0
x2 = 0.0
x3 = 0.0
x4 = 0.0
x5 = 0.0
x6 = 0.0
x7 = 0.0
x8 = 1.0
x9 = 0.0

In [28]:
opt.value(prob.objective)


Out[28]:
84541269.716

In [ ]: